﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.享元模式
{
    public class ShapeFactory
    {
        private static Dictionary<string, IShape> circleMap = new Dictionary<string, IShape>();
    
        public static IShape GetCircle(string color)
        {
            IShape circle;
            if (circleMap.ContainsKey(color))
            {
                circle = circleMap[color];
            }
            else
            {
                circle = new Circle(color);
                circleMap.Add(color, circle);
                Console.WriteLine("Creating circle of color : " + color);
            }
            return circle;
        }
    }
}
